//
//  MCOrderDetailShowViewController.swift
//  StoreManage
//
//  Created by MC on 2018/9/4.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit



/**
 * 只可以查看不可编辑的订单详情，比如，自营统计订单查看详情。 分销员查看订单管理详情。
 */

class MCOrderDetailShowViewController: MCViewController {
    
    
    
    var orderSn = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        baseSetting()
        
        initUI()
        
        sendNetworking()
    }
    
    // MARK: - System Delegate
    
    // MARK: - Custom Delegate
    
    // MARK: - Action
    
    // MARK: - Network
    func sendNetworking() {
        let para = [
            "orderSn" : orderSn,
            ] as [String : Any]
        
        MCNetwork_post(url: JAVA_getPersonageCentreListVoDetail, para: para as [String : AnyObject], vc: self,hudSuperView: self.view,isHiddenTabbar: true, success: { (response) in
            let dataDict = response["data"] as! [String : AnyObject]
            
            let model = MCOrderListFatherModel()
            model.setValuesForKeys(dataDict)
            self.headSectionView.model = model
            self.footSectionView.model = model
            self.footerView.model = model
            
            let listBaOrderDetailVo = dataDict["listBaOrderDetailVo"] as! NSArray
            
            // 商品
            for dict in listBaOrderDetailVo {
                let model = MCOrderListModel()
                model.setValuesForKeys(dict as! [String : Any])
                self.dataArrayM.add(model)
            }
            self.tableView.reloadData()
            
        }, dislike: { (response) in }) { (error) in }
    }
    
    // MARK: - Method
    func baseSetting() {
        self.title = "订单详情"
        self.view.backgroundColor = UIColor.white
    }
    
    func initUI() {
        
        view.addSubview(tableView)
        tableView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(view).inset(UIEdgeInsetsMake(0, 0, 0, 0))
        }
        tableView.tableFooterView = footerView
    }
    
    // MARK: - Setter & Getter
    lazy private var tableView: MCTableView = {
        let tableView = MCTableView.init(frame: CGRect.zero, style: UITableViewStyle.grouped)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = UIColor.MCGray_light
        return tableView
    }()
    
    lazy var dataArrayM: NSMutableArray = {
        let arrayM = NSMutableArray()
        return arrayM
    }()
    
    lazy var footerView: MCMallStatisticsDetailFooterView = {
        let view = MCMallStatisticsDetailFooterView()
        view.frame = CGRect.init(x: 0, y: 0, width: 0, height: 120 + 83 + 40)
        return view
    }()
    
    lazy var headSectionView: MCOrderListSectionHeaderView = {
        let view = MCOrderListSectionHeaderView()
        return view
    }()
    
    lazy var footSectionView: MCOrderListSectionFooterView = {
        let view = MCOrderListSectionFooterView()
        return view
    }()
    
}

extension MCOrderDetailShowViewController : UITableViewDelegate,UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 55
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return headSectionView
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 45
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return footSectionView
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArrayM.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = MCOrderListCell.init(style: UITableViewCellStyle.value1, reuseIdentifier: "cell")
        
        cell.selectionStyle = UITableViewCellSelectionStyle.none
        
        cell.model = self.dataArrayM[indexPath.row] as! MCOrderListModel
        
        return cell
    }
}

